//
//  MyAppointInfoViewController.m
//  WeiWeiApp
//
//  Created by 高继鹏 on 15/10/15.
//  Copyright © 2015年 GaoJipeng. All rights reserved.
//

#import "MyAppointInfoViewController.h"
#import "MyAppointInfoCell.h"
#import "PersonInfoViewController.h"

@interface MyAppointInfoViewController (){
    NSMutableArray *tableSource;
    UITableView *_tableView;
}

@end

@implementation MyAppointInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleWithSting:@"我的预约"];
    
    [self addBtnOnNavWithTitle:@"我" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 30, 20) andDirection:left];
    
    _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    _tableView.backgroundColor = BACKGROUDCOLOR;
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([MyAppointInfoCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([MyAppointInfoCell class])];
    [self.view addSubview:_tableView];
    [self createData];
}
-(void)requestData
{
    [self requestWithKeys:@[@"user_id",@"p"] andValues:@[@([[QZUserInfo userId] intValue]),@(self.page)] andUrlKey:@"Appointments/myAppoint" isCache:YES];
}
-(void)request_POST_FinishValue:(id)value tagNSString:(NSString *)tag
{
    NSLog(@"value = %@",value);
    if ([tag isEqualToString:@"Appointments/myAppoint"]) {
        if ([value[@"status"] intValue] == 100) {
            
        }
    }
}
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)createData
{
    tableSource = [[NSMutableArray alloc] init];
    [tableSource addObject:@[@"2015年9月5日  12:00",@"染发",@"0"]];
    [tableSource addObject:@[@"2015年8月15日  13:30",@"染发",@"1"]];
    [tableSource addObject:@[@"2015年7月19日  19:23",@"染发",@"2"]];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_tableView reloadData];
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 108;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PersonInfoViewController *personVc = [[PersonInfoViewController alloc] init];
    personVc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:personVc animated:YES];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tableSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyAppointInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MyAppointInfoCell class]) forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.contentView.backgroundColor = BACKGROUDCOLOR;
    cell.bookTime.textColor    = OneFiveThreeColor;
    cell.bookServer.textColor  = OneFiveThreeColor;
    cell.serverLabel.textColor = FiveOneColor;
    
    cell.dateLabel.text   = tableSource[indexPath.row][0];
    cell.serverLabel.text = tableSource[indexPath.row][1];
    if (tableSource.count != 0) {
        switch ([tableSource[indexPath.row][2] integerValue]) {
            case 0:
            {
                cell.replayLabel.textColor = [UIColor colorWithRed:181.0/255.0 green:89.0/255.0 blue:234.0/255.0 alpha:1.0];
                cell.replayLabel.text = @"等待设计师回复";
            }
                break;
            case 1:
            {
                cell.replayLabel.textColor = OneFiveThreeColor;
                cell.replayLabel.text = @"预约成功";
            }
                break;
            case 2:
            {
                cell.replayLabel.textColor = OneFiveThreeColor;
                cell.replayLabel.text = @"交易完成";
            }
                break;
            default:
                break;
        }
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
